#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# Copyright @ 2014 OPS, Qunar Inc. (qunar.com)
#
# Author: tingfang.bao <tingfang.bao@qunar.com>
# DateTime: 15-3-9 上午11:53
from flask import Blueprint, render_template, abort
from jinja2 import TemplateNotFound

# 如果讲simple_blueprint注册到app根下，需要指定static_url_path
# simple_blueprint = Blueprint("simple",
#                              __name__,
#                              template_folder='templates',
#                              static_folder='static',
#                              static_url_path="/mb/static")

simple_blueprint = Blueprint("simple",
                             __name__,
                             template_folder='templates',
                             static_folder='static')


@simple_blueprint.route('/', methods=['GET'])
def index():
    try:
        # 这里定位到是blueprint所在的目录
        print simple_blueprint.root_path

        # 读取blueprint中的文件内容
        with simple_blueprint.open_resource("static/style.css") as f:
            print f.read()
        return render_template('index.html', message="simple_blueprint")
    except TemplateNotFound:
        abort(404)